package org.ace.logic.user.impl;

import javax.annotation.Resource;

import io.netty.channel.Channel;

import org.ace.biz.user.IShopBiz;
import org.ace.endingCode.SocketModel;
import org.ace.logic.IHandlerServ;
import org.ace.logic.user.AbstractUserHandlerImpl;
import org.ace.logic.user.dto.BuyItemDTO;
import org.ace.logic.user.protocol.ShopProtocol;
import org.ace.tool.IExecutorPool;

public class ShopHandlerServImpl extends AbstractUserHandlerImpl implements
		IHandlerServ {

	@Resource(name="executorPool")
	private IExecutorPool executorPool;
	
	@Resource(name="shopBiz")
	private IShopBiz shopBiz;
	
	@Override
	public void Colse(Channel channel) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void process(Channel channel, SocketModel message) {
		switch(message.getCommand())
		{
		case ShopProtocol.BUY_CREQ :
			buy(channel,message);
			break;
		}

	}

	private void buy(final Channel channel, SocketModel<BuyItemDTO> message) {
		final Integer userId = getUserId(channel);
		final Integer gdCode = message.getMessage().gdCode;
		final Integer count = message.getMessage().count;
		executorPool.execute(new Runnable() {
			
			@Override
			public void run() {
				write(channel ,ShopProtocol.BUY_SRES,shopBiz.buy(userId, gdCode, count));
				
			}
		});
		
	}

}
